#include "UniformRealDistribution.h"

UniformRealDistribution::UniformRealDistribution(double lowerbound, double upperbound) {
    generator = new boost::random::random_device;
    distribution = new boost::random::uniform_real_distribution<double>(lowerbound, upperbound);
    variate_generator = new boost::variate_generator < boost::random::random_device&, boost::random::uniform_real_distribution<double> > (*generator, *distribution);
}

UniformRealDistribution::~UniformRealDistribution() {
    delete variate_generator;
    delete distribution;
    delete generator;
}

double UniformRealDistribution::Sample() {
    return variate_generator->operator ()();
}

double UniformRealDistribution::min() {
    return distribution->min();
}

double UniformRealDistribution::max() {
    return distribution->max();
}

/**
 * Retorna um double ~ U[lowerbound, upperbound)
 * @param lowerbound limite inferior
 * @param upperbound limite superior
 * @return um double ~ U[lowerbound, upperbound)
 */
double UniformRealDistribution::rand(double lowerbound, double upperbound) {
    UniformRealDistribution * obj = new UniformRealDistribution(lowerbound, upperbound);
    double d = obj->Sample();
    delete obj;
    return d;
}
